2020-2021 Sunseeker Telemetry and Lighting System
usci_b_i2c_ex2_slaveRxMultiple.c
Go to the documentation of this file.
1 /* --COPYRIGHT--,BSD
2  * Copyright (c) 2017, Texas Instruments Incorporated
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * * Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  *
12  * * Redistributions in binary form must reproduce the above copyright
13  * notice, this list of conditions and the following disclaimer in the
14  * documentation and/or other materials provided with the distribution.
15  *
16  * * Neither the name of Texas Instruments Incorporated nor the names of
17  * its contributors may be used to endorse or promote products derived
18  * from this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
27  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
28  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
29  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
30  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  * --/COPYRIGHT--*/
32 #include "driverlib.h"
33 //*****************************************************************************
50 //
51 //*****************************************************************************
52 //*****************************************************************************
53 //
54 //Set the address for slave module. This is a 7-bit address sent in the
55 //following format:
56 //[A6:A5:A4:A3:A2:A1:A0:RS]
57 //
58 //A zero in the "RS" position of the first byte means that the master
59 //transmits (sends) data to the selected slave, and a one in this position
60 //means that the master receives data from the slave.
61 //
62 //*****************************************************************************
63 #define SLAVE_ADDRESS 0x48
64 
65 
66 uint8_t store[40] = { 9, 10, 11, 12, 13, 14, 15, 16, 17, 18};
68 
69 void main ()
70 {
71  //Stop WDT
72  WDT_A_hold(WDT_A_BASE);
73 
74  //Assign I2C pins to USCI_B0
75  GPIO_setAsPeripheralModuleFunctionInputPin(
76  GPIO_PORT_P3,
77  GPIO_PIN1 + GPIO_PIN2
78  );
79 
80  //Initialize I2C as a slave device
81  USCI_B_I2C_initSlave(USCI_B0_BASE,
83  );
84 
86 
87  //Specify transmit mode
88  USCI_B_I2C_setMode(USCI_B0_BASE,
89  USCI_B_I2C_RECEIVE_MODE
90  );
91 
92  //Enable I2C Module to start operations
93  USCI_B_I2C_enable(USCI_B0_BASE);
94 
95  //Enable interrupts
96  USCI_B_I2C_clearInterrupt(USCI_B0_BASE,
97  USCI_B_I2C_RECEIVE_INTERRUPT +
98  USCI_B_I2C_STOP_INTERRUPT
99  );
100  USCI_B_I2C_enableInterrupt(USCI_B0_BASE,
101  USCI_B_I2C_RECEIVE_INTERRUPT +
102  USCI_B_I2C_STOP_INTERRUPT
103  );
104 
105  while (1)
106  {
107  //Enter low power mode 0 with interrupts enabled.
108  __bis_SR_register(LPM0_bits + GIE);
109  __no_operation();
111  }
112 }
113 
114 //******************************************************************************
115 //
116 //This is the USCI_B0 interrupt vector service routine.
117 //
118 //******************************************************************************
119 #if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
120 #pragma vector=USCI_B0_VECTOR
121 __interrupt
122 #elif defined(__GNUC__)
123 __attribute__((interrupt(USCI_B0_VECTOR)))
124 #endif
125 void USCI_B0_ISR (void)
126 {
127  switch (__even_in_range(UCB0IV,12)){
128  case USCI_I2C_UCRXIFG:
129  //receive data
130  *receivedDataPointer++ = USCI_B_I2C_slaveGetData(
131  USCI_B0_BASE);
132  break;
133 
134  case USCI_I2C_UCSTPIFG:
135  __bic_SR_register_on_exit(LPM0_bits);
136  break;
137  }
138 }
139 
__no_operation()
__bic_SR_register_on_exit(LPM3_bits|GIE)
uint8_t * receivedDataPointer
void USCI_B0_ISR(void)
uint8_t store[40]
#define SLAVE_ADDRESS